package wt.hpad;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import wt.hpad.model.bean.DishDetail;
import wt.hpad.utils.DialogUtil;
import wt.hpad.utils.SPUtil;

/**
 * 静态值
 * Created by wt on 12.19.
 */

public class ConstantFields {
    /**
     * 暂时用作"就餐人数"
     */
    public static String TEMPSTRING = "1";
    // basic info
    //    public static String SERVER = "10.93.130.18";
    public static String SERVER = "10.0.2.2";
    public static final String HTTP_PORT = ":8080/";
    public static final String PROJECTNAME = "ct2017/";
    public static String HTTP_URL = "http://" + SERVER + HTTP_PORT + PROJECTNAME;
    public static final String CFILE = "config";
    public static String DEVICEID = "11";

    // msg type
    public static final String MSG_UNTABLE = "untable";  // 未开台
    public static final String MSG_LOGIN = "login";
    public static final String MSG_ADD = "add";
    public static final String MSG_RETURN = "return";
    public static final String MSG_MENU = "menu";
    public static final String MSG_TABLE = "table";
    public static final String MSG_TABLE_ONE = "tableone";
    public static final String MSG_TYPE = "type";   // 菜品分类
    //
    public static int[] SHOW_ITEMS; // 显示项过滤(是否显示:已上,未上,已退)

    // item type
    // 1、未上、2、已上、3、退菜、4、赠送 、5、保留
    public static final int ITEM_TYPE_SERVING = 1; // 未上
    public static final int ITEM_TYPE_SERVED = 2; // 已上
    public static final int ITEM_TYPE_RETREAT = 3; // 已退

    // 内存持久化的值
    public static String CURRENT_TABLE = "";
    public static List<DishDetail> CART_CURRENT;


    public static ViewGroup ORDERVIEW_PARENTVIEWGROUP = null;
    public static View ORDERVIEW_ENDVIEW = null;
    public static TextView ORDERVIEW_CART_NUM = null;


    public static void cleanCacheView() {
        ORDERVIEW_PARENTVIEWGROUP = null;
        ORDERVIEW_ENDVIEW = null;
        ORDERVIEW_CART_NUM = null;
    }

    public static void cleanCacheData() {
        if (CART_CURRENT != null) {
            CART_CURRENT.clear();
            CART_CURRENT = null;
        }
    }

    public static void initShowItems(Context context) {
        String show = SPUtil.getStringValue(context, CFILE, "show");
        if (!TextUtils.equals(show, "")) {
            String[] split = show.split(",");
            SHOW_ITEMS = new int[split.length];
            for (int i = 0; i < split.length; i++) {
                SHOW_ITEMS[i] = Integer.parseInt(split[i]);
            }
        }
    }

    public static void setShowItems(Context context, String content) {
        if (!TextUtils.equals(content, "")) {
            SPUtil.putStringValue(context, CFILE, "show", content);
            initShowItems(context);
        }
    }

    public static void initBasicInfo(Context context) {
        SERVER = SPUtil.getStringValue(context, CFILE, "server");
        if (TextUtils.isEmpty(SERVER)) {
            DialogUtil.showInToast(context, "服务器未设置");
        }
        HTTP_URL = "http://" + SERVER + HTTP_PORT + PROJECTNAME;
        DEVICEID = SPUtil.getStringValue(MainApp.getContext(), CFILE, "device");
    }

    public static void setBasicInfo(Context context, String key, String value) {
        SPUtil.putStringValue(context, CFILE, key, value);
        initBasicInfo(context);
    }

    public static String getBasicInfo(String key) {
        return SPUtil.getStringValue(MainApp.getContext(), CFILE, key);
    }


}
